home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / King of Swing / MusicClasses.h < prev   
Encoding:
Text File  |  2001-06-23  |  2.3 KB  |  111 lines

  1. //    MIDIClasses.h
  2. //     A file devoted to developing an appropriate song data structure which eventually
  3. //     can be translated to MIDI
  4.  
  5. #ifndef __MUSICCLASS_
  6. #define __MUSICCLASS_
  7.  
  8. #include <fstream.h>
  9. #define nil 0
  10.  
  11. //enum VoiceStyle { CHORD
  12. long min(long a, long b);
  13.  
  14. class Instrument {
  15.     public:
  16.         int pFlatness;
  17.         int pAverage;
  18.         int pContinuity;
  19.         int pPeriod;
  20.         
  21.         int sFlatness;
  22.         int sAverage;
  23.         int sContinuity;
  24.         int sPeriod;
  25.         
  26.         char InstNum;
  27.         
  28.         
  29.         int    index;
  30. };
  31.  
  32. class Note {
  33.     public:
  34.         Note() {}
  35.         Note(short pitch, long duration);
  36.         void OutputToFile(ofstream& outFile);
  37.         short     pitch;
  38.         long    duration;
  39.         char     volume;
  40. };
  41.  
  42. class Measure {
  43.     public:
  44.         Measure() {numNotes = 0;}
  45.         void OutputToFile(ofstream& outFile, int measureNum);
  46.         int AddNote(Note newNote);    //returns numNotes
  47.         int GetNumNotes();
  48.         Note getStackedNote(int n);
  49.         void setStackedNoteV(int n, char volume) {if (numNotes >= n) noteLine[numNotes - n].volume = volume;}
  50.         void setStackedNoteP(int n, short pitch) {if (numNotes >= n) noteLine[numNotes - n].pitch = pitch;}
  51.     private:
  52.         int     numNotes;
  53.         Note    noteLine[16];
  54. };
  55.  
  56. class PitchLine {
  57.     public:
  58.         PitchLine() {}
  59.         PitchLine(PitchLine* pitchLineNext, ifstream& fin);
  60.         PitchLine*&    getNext() {return next;}
  61.         int    getPitch(int forThis) {return pitchFunc[forThis];}
  62.     private:
  63.         int         pitchFunc[64];
  64.         PitchLine*     next;
  65. };
  66.  
  67. class SyncLine {
  68.     public:
  69.         SyncLine() {}
  70.         SyncLine(SyncLine* next, PitchLine* corrLine, ifstream& fin);    
  71.         SyncLine*&    getNext() {return next;}
  72.         int    getSync(int forThis) {return syncFunc[forThis];}
  73.     private:
  74.         int         syncFunc[64];
  75.         SyncLine*     next;  
  76. };
  77.  
  78. class Unit {
  79.     public:
  80.         Unit() {pList = nil; sList = nil; nextUnit = nil;}
  81.         Unit(ifstream& fin);                //does all the work
  82.         ~Unit() {}            //does nothing interesting
  83.         
  84.         void OutputToFile(ofstream& outFile);
  85.         Unit*& getNext() {return nextUnit;}
  86.         long CountNumBytes();
  87.     private:
  88.         PitchLine*     pList;
  89.         SyncLine*    sList;
  90.         Measure        mArray[12];
  91.         
  92.         Unit*        nextUnit;
  93.         
  94.         void WriteMeasures(ifstream& fin);
  95.         Note PickNote(int measurecount, PitchLine* pl, SyncLine* sl, int beat, char random);
  96. };
  97.  
  98. class Song {
  99.     public:    
  100.         Song ();
  101.         Song(ifstream& fin);
  102.         ~Song() {}
  103.         
  104.         void OutputToFile(ofstream& outFile);
  105.         long CountNumBytes();                    //the MTrk chunk needs to know its length
  106.         
  107.     private:
  108.         Unit*         headPointer;
  109. };
  110.  
  111. #endif